import React, { useEffect } from 'react';
import ReactDOM from 'react-dom/client';
import { initScript } from 'dingtalk-docs-cool-app';

function App() {
  useEffect(() => {
    let currentPath = process.env.NODE_ENV == 'development' ? 'http://localhost:3000' : getPath();
    initScript({ 
      scriptUrl: new URL(`${currentPath}/static/js/script.code.js`, window.location.href) 
    });
  }, []);
  
  return null;
}

function getPath() { 
  var href = location.href;
    href = href.split("#")[0];
    href = href.split("?")[0];
    var ss = href.split("/");
    ss.length = ss.length - 1;
  href = ss.join("/");
  return href;
}

const root = ReactDOM.createRoot(document.getElementById('root_script') as HTMLElement);
root.render(
    <App />
);